#!/bin/sh
#
# Copyright (c) 2015 xiaohu@elecirc.com.
#
# This file is part of ZetaWeb project.
#
if [ ! -d public ] ; then
  echo "No public directory found, check if you run $0 in right directory?"
  exit 1
fi

# install jquery module
if [ ! -d node_modules/jquery ] ; then
  echo "Install jquery module ..."
  npm install jquery
fi

# copy jquery assets into public directory
if [ ! -f public/javascripts/jquery.min.js -o \
  ! -f public/javascripts/jquery.min.map ] ; then
  echo
  echo "Copy JQuery assets..."

  mkdir -p ./public/javascripts
  cp -f node_modules/jquery/dist/jquery.min.js ./public/javascripts
  cp -f node_modules/jquery/dist/jquery.min.map ./public/javascripts
fi

# install bootstrap module
if [ ! -d node_modules/bootstrap ] ; then
  echo "Install bootstrap module ..."
  npm install bootstrap
fi

# copy bootstrap assets into public directory
if [ ! -f public/javascripts/bootstrap.min.js ] ; then
  echo
  echo "Copy Bootstrap assets..."

  mkdir -p ./public/javascripts
  cp -f node_modules/bootstrap/dist/js/bootstrap.min.js \
    ./public/javascripts

  mkdir -p ./public/stylesheets
  cp -f node_modules/bootstrap/dist/css/bootstrap.min.css \
    ./public/stylesheets
  cp -f node_modules/bootstrap/dist/css/bootstrap-theme.min.css \
    ./public/stylesheets

  cp -fr node_modules/bootstrap/dist/fonts ./public
fi
